package com.bjpowernode.boss.common.utils;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

public class JwtUtil {
    public static final String SIGN = "abc";

    public static String createJwt(String person, int timeoutMinute) {
        Map<String, Object> header = new HashMap<>();
        header.put("alg", "HS256");
        header.put("typ", "JWT");
        DateTime expireDate = DateUtil.offsetMinute(new Date(), timeoutMinute);
        return JWT.create()
                .withHeader(header)
                .withExpiresAt(expireDate)
                .withClaim("person", person)
                .sign(Algorithm.HMAC256(SIGN));
    }
}
